/**
 * 
 */
package org.crazydays.i18n;


import junit.framework.TestCase;

/**
 * MessagesUnitTest
 */
public class MessagesUnitTest
    extends TestCase
{
    /**
     * Set message properties.
     */
    public void setUp()
    {
        System.getProperties().put(Messages.PROPERTY_MESSAGES_PATH,
            "testmessages");
    }

    /**
     * Test getMessage(String).
     */
    public void testGetMessage_unset()
    {
        // setup
        Messages messages = Messages.getInstance();
        assertNotNull("messages == null", messages);

        // test
        String message = messages.getMessage("unset");
        assertEquals("message != [UNSET]", "[UNSET]", message);
    }

    /**
     * Test getMessage(String).
     */
    public void testGetMessage_set()
    {
        // setup
        Messages messages = Messages.getInstance();
        assertNotNull("messages == null", messages);

        // test
        String message = messages.getMessage("test.example");
        // see tst/src/example.properties
        assertEquals("message != foo", "foo", message);
    }

    /**
     * Test format(String).
     */
    public void testFormat_0()
    {
        // setup
        Messages messages = Messages.getInstance();
        assertNotNull("messages == null", messages);

        // test
        String message = messages.format("test.format.0");
        // see tst/src/example.properties
        assertEquals("message != foobar", "foobar", message);
    }

    /**
     * Test format(String,int).
     */
    public void testFormat_1()
    {
        // setup
        Messages messages = Messages.getInstance();
        assertNotNull("messages == null", messages);

        // test
        String message = messages.format("test.format.1", 1);
        // see tst/src/example.properties
        assertEquals("message != foobar1", "foobar1", message);
    }

    /**
     * Test format(String,int,int).
     */
    public void testFormat_2()
    {
        // setup
        Messages messages = Messages.getInstance();
        assertNotNull("messages == null", messages);

        // test
        String message = messages.format("test.format.2", 1, 2);
        // see tst/src/example.properties
        assertEquals("message != 2foobar1", "2foobar1", message);
    }
}
